import { Component, OnInit, Injector } from '@angular/core';
import { ZoneComputer } from 'app/modules/zone/services/zone.service';
import { ZoneResourceListBase } from '../zone-list-base';
import { ComputerService } from 'app/modules/computer/services/computer.service';

@Component({
  selector: 'm-zone-computer-list',
  templateUrl: './zone-computer-list.component.html',
  styleUrls: ['./zone-computer-list.component.scss'],
})
export class ZoneComputerListComponent extends ZoneResourceListBase<ZoneComputer> {
  constructor(private injector: Injector, private computerService: ComputerService) {
    super(injector, 'pc');
  }

  async disable(...cid: number[]) {
    if (!cid.length) {
      cid = this.selection.keys();
    }
    await this.computerService.batch('status', this.EnableStatus.Disable, cid);
  }
  async enable(...cid: number[]) {
    if (!cid.length) {
      cid = this.selection.keys();
    }
    await this.computerService.batch('status', this.EnableStatus.Enable, cid);
  }

  upgrade(...cid: number[]) {
    if (!cid.length) {
      cid = this.selection.keys();
    }
    return this.computerService.upgrade({ computerIDs: cid, zoneIDs: [this.zone.id] });
  }
}
